﻿using System;
using System.Data;
using System.Web.UI;
using DevExpress.Web;
using System.Web.UI.WebControls;

public partial class MyReservations : MemberPage
{
   

    protected void Page_Init(object sender, EventArgs e)
    {
        Bind();
    }
    protected void Page_Load(object sender, EventArgs e)
    {

        GridViewDataColumn gcImg = (GridViewDataColumn)gvRezerve.Columns["Scan"];
        if (gcImg != null)
            gcImg.DataItemTemplate = new Utils.PhotoColumnTemplate();
 
        if (!Page.IsPostBack)
        {
            if (gvRezerve.Columns["OrderRef"] != null)
                gvRezerve.GroupBy(gvRezerve.Columns["OrderRef"]);
        }
        
    }

    private void Bind()
    {
        DataTable dt = DataAccess.web2GetReservation();
        gvRezerve.DataSource = dt;

        ConfExpertMaster m = (ConfExpertMaster)Master;
        m.TableToExport = dt;

        gvRezerve.Columns.Clear();
        gvRezerve.TotalSummary.Clear();

        foreach (DataColumn col in dt.Columns)
        {
            string colName = col.ColumnName.ToLower();
            if (colName == "productıd")
            {
                GridViewDataColumn gcImg = new GridViewDataColumn();
                gcImg.DataItemTemplate = new Utils.PhotoColumnTemplate();
                gcImg.Caption = "Scan";
                gcImg.CellStyle.Paddings.Padding = 1;
                gcImg.Width = 33;
                gcImg.CellStyle.HorizontalAlign = System.Web.UI.WebControls.HorizontalAlign.Center;
                gvRezerve.Columns.Add(gcImg);
            }
            else
            {
                GridViewDataTextColumn gc = new GridViewDataTextColumn();
                gc.FieldName = col.ColumnName;
                gc.Settings.AutoFilterCondition = AutoFilterCondition.Contains;

                if (colName != "description")
                    gc.CellStyle.Wrap = DevExpress.Utils.DefaultBoolean.False;

                ASPxSummaryItem summary;
                if (colName == "article")
                {
                    summary = new ASPxSummaryItem(gc.FieldName, DevExpress.Data.SummaryItemType.Count);
                    summary.ShowInColumn = col.ColumnName;
                    summary.DisplayFormat = "∑ {0:n0} article(s)";
                    gvRezerve.TotalSummary.Add(summary);
                }

                if (colName.Contains("price"))
                {
                    gc.CellStyle.HorizontalAlign = System.Web.UI.WebControls.HorizontalAlign.Right;
                }

                else if (colName.Contains("qty") || colName.Contains("total"))
                {
                    gc.PropertiesTextEdit.DisplayFormatString = "#,#.0;#,#.0; ;";
                    gc.Settings.AutoFilterCondition = AutoFilterCondition.GreaterOrEqual;
                    summary = new ASPxSummaryItem(gc.FieldName, DevExpress.Data.SummaryItemType.Sum);
                    summary.DisplayFormat = "∑ {0:n1} mt(s).";
                    summary.ShowInColumn = col.ColumnName;
                    gvRezerve.TotalSummary.Add(summary);
                }

                gvRezerve.Columns.Add(gc);
            }
        }

        gvRezerve.Styles.AlternatingRow.Enabled = DevExpress.Utils.DefaultBoolean.True;

        gvRezerve.DataBind();
    }

   

    protected void gvAyrim_DataBound(object sender, EventArgs e)
    {
        ASPxGridView gvAyrim = (ASPxGridView)sender;
        //((GridViewDataColumn)gvAyrim.Columns["ReservedQty"]).PropertiesEdit.DisplayFormatString = "{0:n2}";
    }
}